package com.vca.admin.controller;

import com.vca.common.page.CommonPage;
import com.vca.common.request.InvoicePageRequest;
import com.vca.common.request.InvoiceRequest;
import com.vca.common.response.*;
import com.vca.common.result.CommonResult;
import com.vca.service.service.InvoiceRecordService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Li
 * @description 发票小程序控制器
 * @date 2023-02-10 15:06
 */

@Slf4j
@RestController("InvoiceController")
@RequestMapping("api/admin/invoice")
@Api(tags = "发票后台控制器")
public class InvoiceController {

    @Autowired
    private InvoiceRecordService invoiceRecordService;

    /**
    * @description 发票分页
    * @param request
    * @author Li
    * @date 2023/2/10 18:30
    * @return {@link CommonResult}<{@link CommonPage}<{@link InvoicePageResponse}>>
    */
    @PreAuthorize("hasAuthority('admin:invoice:page')")
    @ApiOperation("发票分页")
    @PostMapping("/page")
    public CommonResult<CommonPage<InvoicePageResponse>> page(@RequestBody InvoicePageRequest request){
        return CommonResult.success(CommonPage.restPage(invoiceRecordService.invoicePage(request)));
    }

    /**
    * @description 发票订单
    * @param id
    * @author Li
    * @date 2023/2/13 9:53
    * @return {@link CommonResult}<{@link List}<{@link InvoiceOrderResponse}>>
    */
    @PreAuthorize("hasAuthority('admin:invoice:order')")
    @ApiOperation("发票订单")
    @GetMapping("/invoiceOrder")
    @ApiImplicitParams({
           @ApiImplicitParam(name = "id", value = "发票id",required = true,dataType = "int")
    })
    public CommonResult<List<InvoiceOrderResponse>> invoiceOrder(Integer id){
        return CommonResult.success(invoiceRecordService.invoiceOrder(id));
    }
}
